<div style="padding:0 20px 20px 20px;width: 600px;" class='wttai_ajax_center'>
    <h3 style='text-align: center;padding-top: 20px;'>{$site.title}</h3>
    <div class="data-table table-striped">
        <table class="site_channel">
            <thead>
                <tr>
                    <th>排序</th>
                    <th class="row-selected">
                        <!--<input class="checkbox" type="checkbox">-->
                    </th>
                    <th>导航名称</th>
                    <th>导航地址</th>
                </tr>
            </thead>
            <tbody>
            <notempty name="list">
                <volist name="list" id="channel">
                    <tr>
                        <td>
                            <input type="number" site_id="{$site.id}" channel_id="{$channel.id}" class="change_sort text input-mini" value="{$site_channel[$channel['id']]|default=0}" name="sort[]">
                        </td>
               
                        <if condition="isset($site_channel[$channel['id']])">
                            <assign name="input_checked" value="checked" />
                        <else />
                            <assign name="input_checked" value="" />
                        </if>
                    
                        <td><input  site_id="{$site.id}"  class="ids row-selected" {$input_checked} type="checkbox" name="" id="" value="{$channel['id']}"> </td>
                        
                        <td><a target="_blank" href="{:U('Channel/edit?id='.$channel['id'].'&pid='.$channel['pid'])}">{$channel.title}</a></td>
                        <td>{$channel.url}</td>
                    </tr>
                </volist>
                <else/>
                <td colspan="6" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('.wttai_ajax_center .site_channel input[type="checkbox"]').on('change', function(){
            var checked = $(this).is(':checked')?1:2;
            var val = $(this).val();
            var site_id = $(this).attr('site_id');
            
             var url = "{:U('Site/setChannelInfo')}";
            
            var data = {
                "channel_id":val,
                "site_id":site_id,
                "checked":checked 
            };
            
            $.ajax({
                "url":url,
                "data":data,
                "success":function(tip){
                    console.log(tip);
                },
                "error":function() {
                    console.log(arguments);
                }
            });
            
        });
        $('.wttai_ajax_center .site_channel input.change_sort').on('change', function(){
            var val = parseInt($(this).val());
            if (val < 0) {
                $(this).val(0);
                val = 0;
            }
            
            var channel_id = $(this).attr('channel_id');
            var site_id = $(this).attr('site_id');
            var checked = 1;
            $('input[value="'+channel_id+'"]').attr('checked', true);
            
            var url = "{:U('Site/setChannelInfo')}";
            
            var data = {
                "channel_id":channel_id,
                "site_id":site_id,
                "checked":checked,
                "sort":val  
            };
            
            $.ajax({
                "url":url,
                "data":data,
                "success":function(tip){
                    console.log(tip);
                },
                "error":function() {
                    console.log(arguments);
                }
            });
            return false;
        });
    });
</script>
